package online.shenme.day05.test;

import java.util.Scanner;

public class Email {
    public static void main(String[] args) {
        System.out.println("请输入邮箱：");
        String email = new Scanner(System.in).nextLine();
        char[] mails = email.toCharArray();
        boolean flag = false;

        flag = isFlag(mails, flag);
        if (flag) {
            System.out.println("Email合法");
        } else {
            System.out.println("Email不合法");
        }
    }

    private static boolean isFlag(char[] mails, boolean flag) {
        for (int i = 0; i < mails.length; i++) {
            if (mails[i] == '@') {
                for (int j = i + 2; j < mails.length - 1; j++) {
                    if ((mails[j] == '.') && (mails[j + 1] == '.')) {
                        break;
                    } else {
                        if ((mails[j] == '.') && (mails[j + 1] != '.')) {
                            flag = true;
                            break;
                        }
                    }
                }
            }
        }
        return flag;
    }
}
